<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::table('task_applications', function (Blueprint $table) {
            if (Schema::hasColumn('task_applications', 'address')) {
                $table->dropColumn('address');
            }
            if (Schema::hasColumn('task_applications', 'skills')) {
                $table->dropColumn('skills');
            }
            if (Schema::hasColumn('task_applications', 'education')) {
                $table->dropColumn('education');
            }
            if (Schema::hasColumn('task_applications', 'emergency_contact')) {
                $table->dropColumn('emergency_contact');
            }
            if (Schema::hasColumn('task_applications', 'emergency_phone')) {
                $table->dropColumn('emergency_phone');
            }
        });
    }

    public function down(): void
    {
        Schema::table('task_applications', function (Blueprint $table) {
            if (! Schema::hasColumn('task_applications', 'address')) {
                $table->string('address', 500)->nullable()->comment('地址');
            }
            if (! Schema::hasColumn('task_applications', 'skills')) {
                $table->json('skills')->nullable()->comment('技能');
            }
            if (! Schema::hasColumn('task_applications', 'education')) {
                $table->enum('education', ['high_school', 'college', 'bachelor', 'master', 'doctor'])->nullable()->comment('学历');
            }
            if (! Schema::hasColumn('task_applications', 'emergency_contact')) {
                $table->string('emergency_contact')->nullable()->comment('紧急联系人');
            }
            if (! Schema::hasColumn('task_applications', 'emergency_phone')) {
                $table->string('emergency_phone', 20)->nullable()->comment('紧急联系人电话');
            }
        });
    }
};
